﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace Gakita.Controller
{
    /* This Controller deals with calling draw and update on whichever controller is currently active, 
       and switching between them when appropriate */
    class MasterController
    {
        public enum Controllers
        {
            Menu,
            Info,
            Game
        }

        private IController _activeController;
        private GameController _gameController;
        private MenuController _menuController;
        private InfoController _infoController;

        private View.Menu.HighScoreModel _highscoreModel        =       new View.Menu.HighScoreModel();

        public MasterController(GraphicsDeviceManager aGraphics, ContentManager aContentManager)
        {
            SpriteBatch _spritebatch = new SpriteBatch(aGraphics.GraphicsDevice);
            _gameController = new GameController(aGraphics, aContentManager, _spritebatch, _highscoreModel);
            _menuController = new MenuController(aGraphics, aContentManager, _spritebatch, _highscoreModel);
            _infoController = new InfoController(aGraphics, aContentManager, _spritebatch, _highscoreModel);

            // The game starts with the infocontroller displaying the start screen
            _activeController = _infoController;
        }

        public void Draw(float aElapsedTime, Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice)
        {
            _activeController.Draw(aElapsedTime, GraphicsDevice);
        }

        /* This method calls update on the currently active controller, then checks is the controller needs to be changed 
           and which controller to change to */
        public void Update(float aElapsedTime)
        {
            _activeController.Update(aElapsedTime);

            if (_activeController.DidUserChangeController() == true)
            {
                switch (_activeController.ControllerToChangeTo())
                {
                    case Controllers.Game:
                        _activeController = _gameController;
                        break;
                    case Controllers.Menu:
                        _activeController = _menuController;
                        break;
                    case Controllers.Info:
                        _activeController = _infoController;
                        break;
                }
            }
        }

    }
}
